package com.zuo.seckilldemo;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import com.baomidou.mybatisplus.generator.fill.Property;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class GeneratorCode {
    public static void main(String[] args) {
        String[] tableNames = {"sk_goods","sk_goods_seckill","sk_order","sk_order_info"};
        List<String> tables = Arrays.asList(tableNames);
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai","root","123456")
                .globalConfig(builder -> {
                    builder.author("zuogaocan")
                            .enableSwagger()
                            .disableOpenDir()
                            .outputDir(projectPath + "/src/main/java");
                })
                .packageConfig(builder -> {
                    builder.parent("com.zuo")
                            .moduleName("seckilldemo")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,projectPath + "/src/main/resources/mapper"));

                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables)
                            .addTablePrefix("sk_")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .entityBuilder()
                            .addTableFills(new Column("create_time", FieldFill.INSERT))
                            .addTableFills(new Property("updateTime", FieldFill.INSERT_UPDATE))
                            .naming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableFileOverride()
                            .enableRestStyle()
                            .mapperBuilder();
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
